package com.jstide.credit.data.service.biz;

import cn.hutool.core.util.StrUtil;
import cn.hutool.db.Entity;
import com.jstide.credit.data.service.Algorithm;
import lombok.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.ResultSet;
import java.util.List;
import java.util.Optional;

public class Factor32 extends Algorithm {

    private static final Logger logger = LoggerFactory.getLogger(Factor32.class);

    @Getter
    public final  String name="32";

    //欠缴水/电/气费信息
    //存在一次欠费-5分，取值5年内
    //-100
    @Getter
    public  final String sql = " select count(1) as TOTAL from ZRRQJSDQFXX where  join_id=@joinId and  QJTJJZRQ  > trunc(sysdate)-(INTERVAL '5' YEAR)  ";

    @Getter
    public final int defaultScore=-5;

    private final int minScore = -100;

    @Override
    public int translate(String rs) {
        return 0;
    }


    @Override
    public int translate(List<Entity> rs) {
        int result =0;
        try {
            int total =0;
            if(null!=rs && rs.size()>0){
                total =  Optional.ofNullable(rs.get(0).getInt("TOTAL")).orElse(0);
            }
            result = total>0? defaultScore*total:0; ;
            result = result<minScore?minScore:result;
        }
        catch (Exception e){
            logger.error(StrUtil.format("项目{}计算错误：",name),e);
        }
        return result;
    }
}
